package com.ct.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ct.entity.vo.ResponseVO;
import com.ct.service.ReportService;

import jakarta.annotation.Resource;

/**
 * @Description:
 * @Author: cby
 * @Date: 2024/11/29 21:49
 */

@RestController
@RequestMapping("/report")
public class ReportController extends ABaseController {
    @Resource
    private ReportService reportService;

    /**
     *
     * @param start 开始时间
     * @param end   结束时间
     * @return 条形图所需要的数据
     * @throws ParseException 日期格式转化异常
     */
    @RequestMapping("/getBarChart")
    public ResponseVO getBarChartData(String start, String end) throws ParseException {

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date startDate = dateFormat.parse(start);
        Date endDate = dateFormat.parse(end);

        return getSuccessResponseVO(reportService.getBarData(startDate, endDate));
    }

    /**
     *
     * @param start 开始时间
     * @param end   结束时间
     * @return 饼状图所需要的数据
     * @throws ParseException 日期格式转化异常
     */
    @RequestMapping("getPieChart")
    public ResponseVO getPieChartData(String start, String end) throws ParseException {

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date startDate = dateFormat.parse(start);
        Date endDate = dateFormat.parse(end);

        return getSuccessResponseVO(reportService.getPieData(startDate, endDate));
    }

    /**
     *
     * @param start 开始时间
     * @param end   结束时间
     * @return 地图所需要的数据
     * @throws ParseException 日期格式转化异常
     */
    @RequestMapping("getMapChart")
    public ResponseVO getMapChartData(String start, String end) throws ParseException {

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date startDate = dateFormat.parse(start);
        Date endDate = dateFormat.parse(end);

        return getSuccessResponseVO(reportService.getMapData(startDate, endDate));
    }

}
